package modeling.wizards;

import java.io.File;
import java.io.IOException;

import modeling.Activator;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
import org.eclipse.ui.dialogs.FileSelectionDialog;
import org.eclipse.ui.dialogs.FileSystemElement;

import app.MConstants;

public class DesignActivityAnalysisChoosingModelWizardPage extends WizardPage {
	
	private Text fModelText;
	private Text pModelText;
	private Text mModelText;
	
	public DesignActivityAnalysisChoosingModelWizardPage() {
		super("wizardPage");
		setTitle("Choose Models");
		setDescription("Please choose models.");
	}
	
	@Override
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout();
		container.setLayout(layout);
		layout.numColumns = 3;
		layout.verticalSpacing = 9;
		Label label = new Label(container, SWT.NULL);
		label.setText("&Framwork Model:");
		fModelText = new Text(container, SWT.BORDER | SWT.SINGLE);
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		fModelText.setLayoutData(gd);
		Button button = new Button(container, SWT.PUSH);
		button.setText("Browse...");
		button.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				handleBrowse();
			}
		});
		
		Label label1 = new Label(container, SWT.NULL);
		label1.setText("&Project Model:");
		pModelText = new Text(container, SWT.BORDER | SWT.SINGLE);
		pModelText.setLayoutData(gd);
		Button button1 = new Button(container, SWT.PUSH);
		button1.setText("Browse...");
		button1.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				handleBrowse1();
			}
		});
		
		Label label2 = new Label(container, SWT.NULL);
		label2.setText("&Method Model:");
		mModelText = new Text(container, SWT.BORDER | SWT.SINGLE);
		mModelText.setLayoutData(gd);
		Button button2 = new Button(container, SWT.PUSH);
		button2.setText("Browse...");
		button2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				handleBrowse2();
			}
		});
		
		setControl(container);
	}
	
	private void handleBrowse() {
		FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
//			String path = FileLocator.toFileURL(Platform.getBundle("Modeling").getEntry("")).getPath();
//			
//			System.out.println(FileLocator.toFileURL(Platform.getBundle("Modeling").getEntry("")).getPath());
//			System.out.println(ResourcesPlugin.getWorkspace().getRoot());
//			System.out.println(ResourcesPlugin.getWorkspace().getRoot().getFullPath());
//			System.out.println(ResourcesPlugin.getWorkspace().getRoot().getFullPath().toOSString());
			dialog.setFilterPath("/");
		String temp =dialog.open();
		if (temp != null) {
				fModelText.setText(temp);
		}
	}
	
	private void handleBrowse1() {
		FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
			dialog.setFilterPath("\\");
		String temp =dialog.open();
		if (temp != null) {
				pModelText.setText(temp);
		}
	}

	private void handleBrowse2() {
		FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
		dialog.setFilterPath("\\");
		String temp =dialog.open();
		if (temp != null) {
				mModelText.setText(temp);
		}
	}
}
